package note

import (
	"fmt"
	noteServe "forum/app/service/note"
	"forum/app/tools"
	"net/http"
)

// GetList 获取帖子列表
func GetList(w http.ResponseWriter, r *http.Request) {
	params := map[string]interface{}{
		"title": r.FormValue("title"),
		"page":  r.FormValue("page"),
		"limit": r.FormValue("limit"),
	}
	tools.TryCatch(func() {
		data := noteServe.GetNoteList(params)
		tools.OutPutSuccess(w, data)
	}, func(err any) {
		tools.OutPutError(w, fmt.Sprint(err))
	})
}

// GetDetail 获取帖子详情
func GetDetail(w http.ResponseWriter, r *http.Request) {

}

// Create 创建帖子
func Create(w http.ResponseWriter, r *http.Request) {
	data := map[string]any{
		"title":   r.FormValue("title"),
		"content": r.FormValue("content"),
		"user_id": r.FormValue("user_id"),
	}
	tools.TryCatch(func() {
		id := noteServe.NoteCreate(data)
		tools.OutPutSuccess(w, map[string]interface{}{"id": id})
	}, func(err any) {
		tools.OutPutError(w, fmt.Sprint(err))
	})
}

func Update(w http.ResponseWriter, r *http.Request) {

}

func Delete(w http.ResponseWriter, r *http.Request) {

}
